import Vue from 'vue'
import App from './App.vue'
import Vuex from 'vuex'
import VuexPersistence from "vuex-persist";
import router from "./router/Index";
import ElementUI, { Message } from "element-ui"
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios/lib/axios'
import VueParticles from 'vue-particles'
import Print from 'vue-print-nb'


//加载提示信息
Vue.prototype.openLoading = function (text = "数据加载中...") {
    const loading = this.$loading({
        lock: true,
        text: text,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    });
    return loading;
}


import echarts from 'echarts'
//import BaiduMap from 'vue-baidu-map'
//import * as THREE from "three/build/three.module"

ElementUI.Dialog.props.closeOnClickModal.default = false;
/*
import VueSession from 'vue-session'
*/

/*Vue.use(VueSession)*/
Vue.use(ElementUI)
Vue.use(Vuex)
Vue.use(VueParticles)
Vue.use(Print);
//Vue.use(BaiduMap, {
//    // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
//    ak: 'VRRAmlQEWhMlNepCuA3yNcdDgBQ3F2jf'
//});
// 测试地址
// let BasePath = 'http://192.168.3.20:5001/'
let BasePath = 'http://127.0.0.1:5001/'
//let BasePath = 'http://172.20.10.4:5001/'
//正式版本
//let BasePath = 'http://101.204.227.175:93/'

//浏览器的根路径
//axios.defaults.baseURL = 'http://192.168.0.127:101/api/'
axios.defaults.baseURL = BasePath + 'api/'

axios.interceptors.request.use((config) => {
    config.headers.Authorization = "Bearer " + window.sessionStorage.getItem('token');
    config.headers.Power = window.sessionStorage.getItem('Power');
    config.headers.OperProjectid = window.sessionStorage.getItem('OperProjectid');
    return config;
})
//axios拦截器

axios.interceptors.response.use(
    response => {
        // 如果返回的状态码为200，说明接口请求成功，可以正常拿到数据
        // 否则的话抛出错误
        if (response.data.check == false) {
            return Promise.reject(response.data.msgText)
        } else if (response.status === 200) {
            return Promise.resolve(response);
        } else {
            return Promise.reject(response);
        }
    }
);
Vue.prototype.$http = axios
Vue.prototype.$BasePath = BasePath
Vue.prototype.$echarts = echarts
// Vue.prototype.THREE = THREE
//加载提示信息
Vue.prototype.openLoading = function (text = "数据加载中...") {
    const loading = this.$loading({
        lock: true,
        text: text,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    });
    return loading;
}
Vue.config.productionTip = false

const vuexlocal = new VuexPersistence({
    storage: window.localStorage
})

const store = new Vuex.Store({
    state: {
        user: { id: 0, name: '', imageURL: '', roleid: '', roleNumber: '', dutyid: '' },
        webhead: false,
        messcount: 0,
        menulis: [],
        AllUsers: [],
        enumDes: [],
    },
    //同步方法
    mutations: {
        setdata(state, userd) {
            state.user.id = userd.Id;
            state.user.name = userd.UserName;
            state.user.roleid = userd.RoleId;
            state.user.dutyid = userd.UserPosition;
            // state.user.imageURL = userd.imageURL;
        },
        setroledata(state, Remark) {
            state.user.roleNumber = Remark;
        },
        setAllUsers(state, new_AllUsers) {
            state.AllUsers = new_AllUsers
        },
        setMesscount(state, messcount) {
            state.messcount = messcount
        },
        setmenulis(state, newmenulis) {
            state.menulis = newmenulis
        },
        webheadOn(state) {
            state.webhead = true;
        },
        webheadDown(state) {
            state.webhead = false;
        },
        setEnumDes(state, newEnumDes) {
            state.enumDes = newEnumDes
        },
    },
    //异步方法
    actions: {},
    //持久化数据,防止页面刷新丢失数据
    plugins: [vuexlocal.plugin]
})

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
